package algotithm.leetcode.presum.test1310;

/**
 * @author 25068
 * @Date 2021/5/12 9:34
 * @Title 1310. 子数组异或查询
 */
public class Solution {

    public static void main(String[] args) {
        int[] arr = {1,3,4,8};
        int[][] queries = {{0,1},{1,2},{0,3},{3,3}};
        Solution solution = new Solution();
        int[] ans = solution.xorQueries(arr, queries);
        for (int num : ans) {
            System.out.print(num + " ");
        }
    }

    public int[] xorQueries(int[] arr, int[][] queries) {
        int n = arr.length;
        int[] res = new int[n + 1];
        for (int i = 0; i < n; i++) {
            res[i + 1] = res[i] ^ arr[i];
        }
        int m = queries.length;
        int[] ans = new int[m];
        for (int i = 0 ; i < m; i++) {
            ans[i] = res[queries[i][0]] ^ res[queries[i][1] + 1];
        }
        return ans;
    }
}
